<?php

namespace app\logic\index;

class L_article
{
    /** 获取相关文章,按关键字匹配
     * @param $paramObj
     * @return array
     */
    public static function getCorrelationList($paramObj)
    {
        $dataObj = paramsObj();   //创建空对象
        $dataObj->request = paramsObj();  //赋值请求
        $dataObj->data = paramsObj();    //赋值数据
        $dataObj->data->use_trans = false;        //关闭use_trans
        $dataObj->result = array();           //存放结果
        $dataObj = blenderObject($dataObj, $paramObj); //后面覆盖前面的数据，数组进行融合不完全覆盖。
        $final_arr = logInit();
        if ($final_arr["error_no"] == 0) {
            $mixed = parseToArr($paramObj, "mixed", 0); //获取是否混合数据 1混合 0 只用默认
            $params = parseToArr($paramObj, "params", array());//  参数
            $rules = getKeyDefaultRule(array(           //设置规则 如果为空就用默认规则
                'moduleId' => 'require|number',
                'articleId' => 'require|number',
                'size' => ''
            ));

            $messages = getValidateMessage($rules);
            $dataDefault = array();
            $paramsObj = paramsObj();  //新建一个空对象
            $paramsObj->params = $params;
            $paramsObj->mixed = $mixed;
            $paramsObj->rules = $rules;
            $paramsObj->messages = $messages;
            $paramsObj->dataDefault = $dataDefault;

            $checkResult = app("verifyParam")::validatorRequest($paramsObj);
            if ($checkResult["error_no"] == 0) {
                $dataObj->request = $checkResult["result"];
            } else {
                $final_arr = logCallErrorMsg($final_arr, $checkResult);
            }
        }
        if ($final_arr["error_no"] == 0) {
            $paramsObj2 = paramsObj();  //新建一个空对象
            $paramsObj2->params = [
                "id" => $dataObj->request->articleId,
                "moduleId" => $dataObj->request->moduleId
            ];
            $checkResult = app("S_Index_article")->info($paramsObj2);
            if ($checkResult["error_no"] != "0") {
                $final_arr = logCallErrorMsg($final_arr, $checkResult);
            } else {
                $dataObj->request->articleInfo = $checkResult["result"];
            }
        }
        //分割关键字 并获取相关信息
        if ($final_arr["error_no"] == 0) {
            $tempObj2 = paramsObj();  //新建一个空对象
            $tempObj2->params = [
                "moduleId" => $dataObj->request->moduleId,
//                "webKeyWords" => !strpos($dataObj->request->articleInfo["webKeyWords"], ",") ? array($dataObj->request->articleInfo["webKeyWords"]) : explode(",", $dataObj->request->articleInfo["webKeyWords"]),
                "size" => $dataObj->request->size,
            ];
            $checkResult = app("S_Index_article")->getCorrelationList($tempObj2);
            if ($checkResult["error_no"] != "0") {
                $final_arr = logCallErrorMsg($final_arr, $checkResult);
            } else {
                $final_arr["result"] = $checkResult["result"];
            }
        }

        return $final_arr;
    }


}